TRIGGER mysql
use etl;
delimiter |

create trigger secondstr before insert on `error event`
FOR EACH ROW
BEGIN
SET NEW.Seconds_From_Midnight = TIME_TO_SEC(curtime());
END;
|
delimiter ;

TRIGER SQL Server
use etl;
GO
CREATE TRIGGER "TR_SEC_MIDNIGHT"
ON [error event]
FOR INSERT
AS
BEGIN
DECLARE @Id INT; 
select @Id=[iderror Event] from inserted;
UPDATE [etl].[dbo].[error event] set [Seconds_From_Midnight] = DATEDIFF(s,CAST(CAST(YEAR(CURRENT_TIMESTAMP) AS VARCHAR(4)) + '/' +
                CAST(MONTH(CURRENT_TIMESTAMP) AS VARCHAR(2)) + '/' +
                CAST(DAY(CURRENT_TIMESTAMP) AS VARCHAR(2)) AS DATE),current_timestamp) where [etl].[dbo].[error event].[iderror Event] = @Id;
DECLARE @Batch INT;
SELECT @Batch = MAX([idBatch Dimension]) FROM  [etl].[dbo].[batch dimension];
SELECT @Batch = ISNULL(@Batch,-1);
IF @Batch <> -1
	BEGIN
		UPDATE [etl].[dbo].[error event] set [Batch FK] = @Batch where [etl].[dbo].[error event].[iderror Event] = @Id;
	END
           
END;

